@extends('admin.layouts._menu')
@section('content')
    <div class="card">
        <div class="card-body">
            <ul class="nav nav-tabs nav-overflow header-tabs">
                <li class="nav-item">
                    <a href="{{route('admin.goods.index')}}" class="nav-link pb-3 active">
                        商品列表
                    </a>
                </li>
                <li class="nav-item">
                    <a href="{{route('admin.goods.create')}}" class="nav-link pb-3">
                        添加商品
                    </a>
                </li>
            </ul>
        </div>
        <div class="card-body">
            <table class="table">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>商品图片</th>
                    <th>商品名称</th>
                    <th>价格</th>
                    <th>所属分类</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($goods as $good)
                    <tr>
                        <td scope="row">{{$good['id']}}</td>
                        <td><img src="{{$good['picture'][0]}}" style="height: 60px"></td>
                        <td>{{$good['title']}}</td>
                        <td>￥{{$good['price']}}</td>
                        <td>{{$good->makeCategory()}}</td>
                        <td >
                            <div class="btn-group btn-group-sm" role="group" aria-label="First group">
                                {{--<a href="article/{{$v['id']}}/edit" class="btn btn-white">修改</a>--}}
                                <a href="{{route('admin.goods.edit',$good)}}" class="btn btn-light">编辑商品</a>
                                <button type="button" class="btn btn-white" onclick="del(this)">删除商品</button>
                                <form action="{{route('admin.goods.destroy',$good)}}" method="post">
                                    @csrf @method('DELETE')
                                </form>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                <td>{{$goods->links()}}</td>
                </tbody>
            </table>
        </div>
    </div>
@endsection
@push('js')
    <script>
        function del(e) {
            // if (confirm('确定删除吗？')){
            //     $(e).next().submit();
            // }
            require(['hdjs'],function (hdjs) {
                hdjs.confirm('确定删除吗？',function () {
                    $(e).next().submit();
                })
            })
        }
    </script>
@endpush
